<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ page import="com.ce.sys.login.model.User" %>
<%@ page import="com.ce.framework.constants.WebConstants" %>

<%
long ttt = System.currentTimeMillis();
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/sys/main/";

String desktopSrc = com.ce.util.RegeditUtil.getRegeditStringValue("DSEKTOP_PAGE_URL")+"?sid="+request.getSession().getId();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <style type="text/css" media="screen">
    html{height:100%;overflow:hidden;}
    body {behavior:url('<%=path%>/css/csshover.htc');}
    </style>
    <base href="<%=basePath%>"></base>
    <title><%=com.ce.util.RegeditUtil.getRegeditStringValue("SYSTEM_SEG_NAME") %></title>
    <%@ include file="/common/common.jsp"%>
    <link rel="stylesheet" href="<%=path %>/js/jquery-plugin/jquery.autocomplete.css" type="text/css" />
    <script type="text/javascript" src="<%=path %>/js/jquery-plugin/jquery.autocomplete.js"></script>
    <script type="text/javascript" src="<%=path %>/sys/main/main.js"></script>
	<script type="text/javascript">
	        //默认的窗口title文字
	        var defaultWindowTitle = '<%=com.ce.util.RegeditUtil.getRegeditStringValue("SYSTEM_SEG_NAME") %>';
			var refreshTime = <%=com.ce.sys.msg.view.MsgDefine.getInstance(request).getInterval()*1000*60 %>;
			var refreshTitleTime = <%=com.ce.util.RegeditUtil.getRegeditIntValue("SYSTEM_TITLE_REFRESH_TIME")*1000 %>;  //标题刷新间隔时间
			if(refreshTitleTime==0)refreshTitleTime=refreshTime;
		    var msgTimeId = null;  //短消息循环获取对象，
		    //定时回收IE的垃圾内存
		    if (/msie/.test(navigator.userAgent.toLowerCase())) {
                window.setInterval("CollectGarbage();", 300000);
            }
			$(function(){	
		 	//框架自动resize
			$(window).resize(function(){
			    $('#mainFrame').height($(window).height());
			    $('#mainFrame').layout('resize');
			});	
			$(window).resize();
            //构造菜单树，并添加菜单点击事件
            $.getJSON('SysMain_searchUserMenuJsonTree.action?parId=0&t='+new Date().getTime(),function(data){
					for(var i=0;i<data.length;i++){
						$('#menuDiv').append($('<div title="'+data[i].text+'"><ul id="m_'+data[i].id+'"></ul></div>'));
						$('#m_'+data[i].id).tree({
						    data:data[i].children,  //json格式的节点树
							onClick:function(node){
								$(this).tree('toggle', node.target);  //改变选中菜单的样式
								if(node.attributes.url.indexOf('http')>=0){
								   //window.open(node.attributes.url);
								  // return;
								}else if(node.attributes.url!=""){
								    addTab(node.text,node.attributes.url);   
								}
								if(node.attributes.otherInfo==1){
								   $('#mainFrame').layout("collapse",'west');
								}
							}
						});	
					}
					$('#menuDiv').accordion({fit:true});
            });
			
			//查看短消息
			$('#showPopMsg').click(function(){
			     shwoMessage(1);
			});
			
			//退出登录按钮事件	
			$('#exitTabs').click(function(){
			    $.messager.confirm('信息提示', '您确定要退出系统吗?', function(r){
				  if (r){
                     window.location.href='<%=path %>/login/Login_loginOut.action';
				  }
				});
			});	
			
			
			//设置显示所有人员列表的属性窗口
        	$('#allUserWin').window({
		       width:250,
		       height:($(window).height()-80),
		       modal:false,
		       left:($(window).width()-250),
	           top:67
		    });

		    //点击查询人员时的自动完成功能
			$('#searchUser').autocomplete('SysMain_getAllUserJSON.action', { 
					max: 12, //列表里的条目数 
					minChars: 1, //自动完成激活之前填入的最小字符 
					scrollHeight: 300, //提示的高度，溢出显示滚动条 
					matchContains: true, //包含匹配，就是data参数里的数据，是否只要包含文本框里的数据就显示 
					autoFill: false, //自动填充 
					formatItem: function(row, i, max) {
					       return row[1] + '[' + row[2] + ']'; 
					}, 
					formatMatch: function(row, i, max) { 
					       return row[2] ; 
					}, 
					formatResult: function(row) { 
					       return row[2]; 
					}
				}).result(function(event, row, formatted) { 
					    openDialog(row[0],row[1],row[2]); 
			}); 
			
		   //轮询获取系统消息			
            setInterval("shwoMessage()",refreshTime);
           //用户登录后先弹出信息提示
           shwoMessage();
		   //加载在线人员
		   loadOnlineUser();
		   //获取滚动标题的提示信息文字
		   getWindowTitle();
		   //加载右键菜单事件
		   tabCloseEven();
		});	
        //获取所有在线人员
		function loadOnlineUser(){
			$.getJSON('SysMain_getOnlieUser.action?t='+new Date().getTime(),function(data){
				if(!data)return;
				var users = {};
				$('#onlineusernum').text(data.length);
				var ou = $(window).data('onlineUser')||{};
				for(var i=0;i<data.length;i++){
					users[data[i]]=true;
					if(!ou[data[i]]){
						toogleUser(data[i]);
					}
				}
				for(var id in ou){
					if(!users[id]){
						toogleUser(id);
					}
				}
				$(window).data('onlineUser',users);
				setTimeout(loadOnlineUser,refreshTime);
			});
		}
		//更改在线用户的图标颜色
		function toogleUser(id,iconCls){
			var n = $('#userTree').tree('find',id);
			if(n){
				n.iconCls = iconCls||(n.iconCls=='icon-onliman'?'icon-outliman':'icon-onliman');
				var n = $('#userTree').tree('update',n);
			}
		}
		
	    //显示所有人员列表
	    function showAllUser(){
		    $('#allUserWin').window('open');
		    if($('#userTree').text()==''){
			    function dealNodesIcon(ary){//处理节点数组，如果是人员，修改其是否在线的图标
		    		var users = $(window).data('onlineUser')||{};
		    		var n;
		    		for(var i=0;i<ary.length;i++){
			    		var n = ary[i];
		    			if(!n.attributes||!n.attributes.org){//修改人员的图标
			    			n.iconCls = (users[n.id]?'icon-onliman':'icon-outliman');
			    			toogleUser(n.id,(users[n.id]?'icon-onliman':'icon-outliman'));
		    			}
		    		}
			    }
				$('#userTree').tree({
				    url:'<%=path%>/util/util_getOrgTreeNodes.action?showUser=true',  //获取json格式的节点树
				    //打开节点时的操作
				    onClick:function(node){
			    		if(!node.attributes||!node.attributes.org){//
					    	openDialog(node.id,node.text,$('#userTree').tree('getParent',node.target).text.split(' <')[0]);
					    }
					    else if(node.attributes.org&&node.state=='closed'){//加载下级节点
					    	$('#userTree').tree('expand',node.target);
					    }
				    },
				    onLoadSuccess:function(node,data){
				    	if(data&&data.length>0&&data[0].children){
				    		dealNodesIcon(data[0].children);
				    	}
				    },
				    onExpand:function(node){
				    	var ns = $('#userTree').tree('getChildren',node.target);
				    	if(ns.length==1&&ns[0].id=='tmp_loading'){//加载子节点
				    		$.getJSON('<%=path%>/util/util_getOrgTreeNodes.action?showUser=true&pid='+node.id,function(data){
				    			$('#userTree').tree('remove',ns[0].target);
					    		if(data&&data.length>0){
							    	dealNodesIcon(data[0].children);
				    				$('#userTree').tree('append',{parent:node.target,data:data[0].children});
					    		}
				    		});
				    	}
				    },
				    //加载数据失败的处理        
				    onLoadError: function () {    
				        $.messager.alert('消息提示','机构树加载失败，请稍后再试！','error'); 
				    }
				});
		    }
		}
		//获取系统提示信息
		function shwoMessage(flag){
		    flag = flag||0;
            $.post('../msg/SysUserMsgDefine_getMsgString.action?&&t='+new Date().getTime(),{},function(data){
                var msg = "<font color=red>获取提示信息失败！</font>";
			    try{
			        jsonReStr = jQuery.parseJSON(data);  //获取从服务器得到的数据反馈信息
		            msg = jsonReStr.opInfo;
			        if(msg!='' && jsonReStr.opState!="success"){
				        msg = '<font color=red>'+msg+'</font>';
			        }
	            }catch(e){
	               msg = "<font color=red>您的会话已过期或网络链接出现问题，请重新登录后再试！</font>";
	            }finally{	            
		            if(msg!=''){
	                    $.messager.show({
							title:'消息提示',
							msg: msg,
							height:150,
							timeout:20000,  //提示在二十秒后隐藏
							showType:'slide'
						});	
		            }else if(flag!=0&&msg==''){
	                    $.messager.show({
							title:'消息提示',
							msg: '目前没有您需要处理的任务!',
							height:80,
							timeout:5000,  //提示在五秒后隐藏
							showType:'slide'
						});	
		            }
	            }
			});//查询提示信息
			
	    
		   
		   $(window.parent.document).find("#desktop").attr("src",'<%=desktopSrc %>'); 
		}	
		
		function openAboutPage(){
            //默认的打开授权界面操作(添加页面地址，窗口宽度，窗口高度)
            defaultOpenAddPage('../../authorize/about.jsp',546,439,'授权说明','1=1',{maximizable : false,draggable:false});
		}
		
		//打开查看页面
 		function addTabs_(name,url){
 			addTab(name,url); 			
 		}
		
	</script>

<%
System.out.println("===================MAIN_JSP:"+(System.currentTimeMillis()-ttt)); %>
  </head>
  
  <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" rightmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
    	<div id="mainFrame" class="easyui-layout" fit="true" style="width:100%;height:100%;">
			<div region="north" border="false" style="height:67px;background:url(<%=path %>/images/main_bg.jpg) repeat-x center center; overflow:hidden;vertical-align:bottom;text-align:right" class="maintop">
			   <%if(com.ce.framework.util.StringUtil.isNotBlank(com.ce.util.RegeditUtil.getRegeditStringValue("PROJECT_LOGO"))){ %>
                  <div region="logo" class="logo" style="background:url(/<%=com.ce.util.RegeditUtil.getRegeditStringValue("PROJECT_LOGO") %>/images/csmis_logo.png) no-repeat top left;height:67px">
               <%}else{ %>
                  <div region="logo" class="logo" style="background:url(<%=path %>/images/ntax_logo.png) no-repeat top left;height:67px">
               <%} %>   
               
               


               
               <div style="position:relative; top:43px; color:#F0F0F0">
               当前登录：<%=com.ce.sys.login.model.User.getUser(request).getVcName() %>
               【<%= com.ce.sys.login.model.User.getUser(request).getOrgName()%>】
               <font onclick="showAllUser()" style="cursor:pointer" class="fontmans">所有用户</font>
               <a class="easyui-linkbutton" plain="true" iconCls="ext-icon-anchor" id="showPopMsg" style="color:#F0F0F0">消息提示</a>
               <a href="javascript:void(0);" class="easyui-menubutton" data-options="menu:'#layout_north_pfMenu',iconCls:'ext-icon-rainbow'"  style="color:#F0F0F0">更换皮肤</a> 
               <a class="easyui-linkbutton" plain="true" iconCls="icon-exit" id="exitTabs" style="color:#F0F0F0">退出</a>
               
               </div>
               </div>
			</div>
			<div region="west" title="菜单栏" split="true" style="width:200px;overflow:hidden;" >
				<div id="menuDiv">
				</div>
			</div>
			<div region="center"  style="overflow:hidden;">
				<div id="opTabs" class="easyui-tabs" fit="true" border="false">
					<div title="个人桌面">
					  <iframe id="desktop" src="" scrolling="auto" frameborder="0" style="width:100%;height:100%;"></iframe>
					</div>
			    </div>
			</div>    
	    	<div region="south" style="height:28px;background:url(<%=path %>/images/main_bg.jpg) repeat-x bottom left;text-align:center;" class="mainbom"><%=com.ce.util.RegeditUtil.getRegeditStringValue("SYSTEM_SEG_INFO") %>
	    		<% 
	    			if(WebConstants.LICENSE_OPEN){
	    			 out.println("<a class='easyui-linkbutton' plain='true' iconCls='icon-about' id='about'  onClick='openAboutPage();'>&nbsp;</a>");
	    			} 
	    		%>
	    	</div>
		</div> 
	    
	    <div id="layout_north_pfMenu" style="width: 120px; display: none;">
		<div onclick="sy.changeTheme('default');" title="default">default</div>
		<div onclick="sy.changeTheme('gray');" title="gray">gray</div>
		<div onclick="sy.changeTheme('metro');" title="metro">metro</div>
		<div onclick="sy.changeTheme('bootstrap');" title="bootstrap">bootstrap</div>
		<div onclick="sy.changeTheme('black');" title="black">black</div>
		<div class="menu-sep"></div>
		<div onclick="sy.changeTheme('metro-blue');" title="metro-blue">metro-blue</div>
		<div onclick="sy.changeTheme('metro-gray');" title="metro-gray">metro-gray</div>
		<div onclick="sy.changeTheme('metro-green');" title="metro-green">metro-green</div>
		<div onclick="sy.changeTheme('metro-orange');" title="metro-orange">metro-orange</div>
		<div onclick="sy.changeTheme('metro-red');" title="metro-red">metro-red</div>
	</div>
	    
	    
<div style="display:none">

    <div id="allUserWin" title="人员列表" class="easyui-window" closed="true" collapsible="false" minimizable="false" maximizable="false" closable="true">
	    <div style=" border-bottom:1px solid #ccd6c3;padding:2px; background-image:url(<%=path%>/images/div_topbg.jpg); background-position:left bottom; background-repeat:repeat-x; height:22px; padding-top:4px; color:#666 ">
	         <img src="<%=path %>/images/logined.png" width="16" height="16" alt="已登录用户" align="absmiddle">【<%=com.ce.sys.login.listener.LoginUserListener.getLoginUserNumber() %>】
	    </div>
        <div  style=" border-bottom:1px solid #ccc; background-color:#f8fcf6"> 
		     <input id="searchUser" type="text" style="width:180px;"/> 
		     <img src="<%=path %>/images/search.png" width="16" height="16" alt="搜索" style="cursor:pointer">
        </div>
    	<div id="userTree"></div>
    </div>

</div>
    
	<div id="mm" class="easyui-menu" style="width:150px;">
		<div id="mm-tabupdate">刷新</div>
		<div class="menu-sep"></div>
		<div id="mm-tabclose">关闭当前标签页</div>
		<div id="mm-tabcloseother">关闭其它标签页</div>
	    <div id="mm-tabcloseall">全部关闭</div>
		<div class="menu-sep"></div>
		<div id="mm-tabcloseright">关闭右侧标签页</div>
		<div id="mm-tabcloseleft">关闭左侧标签页</div>
	</div>
	
    <div id="dialogWin" closed="true" collapsible="false" minimizable="false" maximizable="false" closable="true"></div>
    </div>
  </body>
</html>
